import Vue from 'vue'
import Vuex from 'vuex'
import { ajax } from './../api/index'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()], // 持久化 Vuex 变成 localStorage 存储在本地
  state: {
    cartNum: 16,
    userInfo: null,
    recommendList: [],
  },
  mutations: {
    changeUserInfo(state, payload) {
      state.userInfo = payload
    },
    getRecommend(state, payload){
      state.recommendList = payload
      console.log(state.recommendList);
    }
  },
  actions: {
    async getRecommendListAction({ commit }, payload){
      let res = await ajax.getRecommendList(payload)
      console.log(res);
      commit('getRecommend', res)
    },
  },
  modules: {
  }
})
